package com.fengke.cn.yejian11.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.fengke.cn.yejian11.R;
import com.fengke.cn.yejian11.activity.TrainDetailActivity;
import com.fengke.cn.yejian11.config.Config;
import com.fengke.cn.yejian11.javabean.Traindown;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/10/7 0007.
 */

public class DegreeAdapter extends RecyclerView.Adapter {
    private List<Traindown> list;
    private Context context;
    public DegreeAdapter(Context context,List<Traindown> list)
    {
        this.context=context;
        this.list=list;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_of_train,viewGroup,false);
        DegreeAdapter.TrainViewHolder holder=new DegreeAdapter.TrainViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        final Traindown trainList=list.get(i);
        DegreeAdapter.TrainViewHolder holder= (DegreeAdapter.TrainViewHolder) viewHolder;
        holder.title.setText(trainList.getName());
        Picasso.with(context).load(Config.PIC_URL+trainList.getThumb()).into(((DegreeAdapter.TrainViewHolder) viewHolder).pic);
        holder.pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, TrainDetailActivity.class);
                intent.putExtra("train_id",trainList.getId());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class  TrainViewHolder extends RecyclerView.ViewHolder{
        ImageView pic;
        TextView title;
        public TrainViewHolder(View itemView) {
            super(itemView);
            pic=(ImageView)itemView.findViewById(R.id.train_pic);
            title=(TextView)itemView.findViewById(R.id.train_title);
        }
    }
}
